## http://en.radzio.dxp.pl/bitmap_converter/
# Use settings
# Byte orientation: Vertical
# Size: Width 128, Height: it depends
# Pixels/byte: 8


custom_logo = bytearray([ \
0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x90, 0xC8, 0xE4, 0xF2, 0xF8, 0xFC, 0x7E, 0x3E, 0x5E, 0x0E,
0x8E, 0x4E, 0x0E, 0x8E, 0xEE, 0xFE, 0xFE, 0xFE, 0xFE, 0x7E, 0x9E, 0xC0, 0xF0, 0x6E, 0x80, 0xC0,
0xC0, 0xE8, 0xF0, 0xF4, 0x78, 0x3C, 0x9C, 0x5E, 0x1E, 0x9E, 0x5E, 0x9E, 0xCE, 0xFE, 0xFE, 0xFE,
0xFE, 0x3E, 0x9E, 0x4E, 0x20, 0x10, 0x04, 0x72, 0x08, 0x32, 0xBA, 0xBC, 0x5E, 0xEE, 0xBE, 0xBE,
0xFE, 0xCE, 0xEE, 0xEE, 0xFE, 0x7E, 0x7E, 0x7E, 0x3E, 0x3E, 0x1E, 0x1E, 0x0E, 0x8E, 0x56, 0x28,
0x80, 0xD6, 0xE2, 0xF0, 0xF0, 0x78, 0x3C, 0x9C, 0x1E, 0x1E, 0x9E, 0x7E, 0x9E, 0x9E, 0xEE, 0xFE,
0xFE, 0xFE, 0x7E, 0x3E, 0xCE, 0xE4, 0x20, 0x84, 0xC2, 0xC0, 0xE8, 0xF0, 0xF4, 0x78, 0x3C, 0x9C,
0x5E, 0x1E, 0x1E, 0x7E, 0x9E, 0xCE, 0xFE, 0xFE, 0xFE, 0xFE, 0x3E, 0x9E, 0x4E, 0x20, 0x10, 0x06,
0x00, 0x34, 0x02, 0x18, 0x1C, 0x3F, 0x3F, 0x0F, 0x4F, 0xEF, 0x0D, 0x4C, 0x7E, 0x3F, 0x3E, 0x5F,
0x2F, 0x0F, 0x17, 0x07, 0x07, 0x03, 0x01, 0x04, 0x02, 0x01, 0x0D, 0x71, 0x04, 0x26, 0x3F, 0x3F,
0x1F, 0x3F, 0x0F, 0x1F, 0x1E, 0x1E, 0x1E, 0x1E, 0x0E, 0x0F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01,
0x00, 0x01, 0x38, 0x0C, 0x00, 0x38, 0x1C, 0x0C, 0x3E, 0x1E, 0x0E, 0x07, 0x07, 0x0B, 0x03, 0x03,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x79, 0x00, 0x06, 0x7F,
0x3F, 0x1F, 0x1F, 0x0F, 0x1F, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x01,
0x01, 0x00, 0x00, 0x0D, 0x71, 0x04, 0x26, 0x3F, 0x3F, 0x1F, 0x3F, 0x0F, 0x1F, 0x1E, 0x1E, 0x1E,
0x1E, 0x1E, 0x0F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00])


clean_pattern = 0x00 # cleaning pattern (0=clean screen,0xFF=black screen,0x55=horizontal stripes)
offset_from_top = 16



##--------------------- do not modify below this line ---------------------------------------------------
import os,sys,struct
print('Running',os.path.basename(sys.argv[0]),'mod...')
fw =  bytearray(open(sys.argv[1],'rb').read())


shellcode = b'\x30\xB5\x55\x22\x06\x49\x07\x48\xF6\xF7\x2A\xFB\x06\x4A\x07\x49\x07\x48\xF6\xF7\x13\xFB\x01\xF0\xAD\xFD\x01\xF0\x6F\xFD\x30\xBD\x00\x04\x00\x00\x84\x06\x00\x20\xCC\xCC\xCC\xCC\xBB\xBB\xBB\xBB\xAA\xAA\xAA\xAA'

shellcode = bytearray(shellcode)
shellcode[2] = clean_pattern   

shellcode = shellcode.replace(struct.pack('<I',0xAAAAAAAA), struct.pack('<I',0x20000684 + (16*offset_from_top)))  #destination of copymem
shellcode = shellcode.replace(struct.pack('<I',0xBBBBBBBB), struct.pack('<I',len(fw)))                            #source of copymem
shellcode = shellcode.replace(struct.pack('<I',0xCCCCCCCC), struct.pack('<I',len(custom_logo)))                   #len of copymem

fw[0x9B3C:0x9B3C+len(shellcode)] = shellcode  # replace boot screen function at address 0x9B3C with above shellcode

fw += custom_logo #append logo at the end of file


#fw[0xD1f0:0xD1f0+2] = b'\xC0\x00'  # 1 second delay
fw[0xD1f0:0xD1f0+2] = b'\x00\x01'  # 2 seconds delay







open(sys.argv[1],'wb').write(fw)

